import constant from "@/common/constant.js";
import { TUIConversationService } from "@tencentcloud/chat-uikit-engine";


//跳转到聊天
function toChat(txCode) {
	getApp().globalData.chatTxCode = txCode;
	const conversationID = `C2C` + txCode;
	uni.$TUIKit.setMessageRead({
		conversationID: conversationID
	}).then(res => {
		const count = uni.$TUIKit.getTotalUnreadMessageCount();
		if (count > 0) {
			uni.setTabBarBadge({
				index: constant.messageIndex,
				text: '' + count
			})
		} else {
			uni.removeTabBarBadge({
				index: constant.messageIndex,
			})
		}
	});
	TUIConversationService.switchConversation(conversationID);
	uni.navigateTo({
		url: `/TUIKit/components/TUIChat/index?conversationID=${conversationID}`,
	});
}

export default {
	toChat
}